#!/bin/sh

echo '/***************************************/'
echo '/* Déplacement dans le répertoire bin/ */'
echo '/***************************************/'
cd bin
echo '/***************************************/'
echo '/*           start registry            */'
echo '/***************************************/'
rmiregistry &
pid_registry=$!
echo 'Registry is running...'
echo 'PID registry is : ' $pid_registry

echo ''
echo '/***************************************/'
echo '/*        Création des noeuds          */'
echo '/***************************************/'
echo ''

# boucle for
for i in {1..11}
do
    echo '*** Creation du noeud '$i' ***'
    java -Djava.security.policy=../mypolicy rmi.graph.SiteImplGraph $i > ../PrintNoeud/creation$i.txt &
    echo '*** Creation du noeud '$i' OK, pid '$!' ***'
    list_pid[$i]=$!
    sleep 0.5
done

echo ''


echo '/***************************************/'
echo '/*        Création des aretes          */'
echo '/***************************************/'
echo ''
#
#					1
#				  /    \
#				 2       3
#			   /   \     |  \
#            4      5    |    9
#          /   \  /  \   |  /  \ 
#         6      7    8 - 10    11
#

echo ''
echo '		  1         '
echo '		/   \        '
echo '	       2     3       '
echo '	      / \     |\      '
echo '             4   5    | 9    '
echo '            / \ / \   |/ \  ' 
echo '           6   7   8--10  11'
echo ''
        
echo '*** Creation arete 1 2 ***'
java -Djava.security.policy=../mypolicy rmi.graph.AreteGraph 1 2 > ../PrintNoeud/A1_2.txt &
echo '*** Creation arete 1 2 OK, pid '$!' ***'
wait $!

echo '*** Creation arete 1 3 ***'
java -Djava.security.policy=../mypolicy rmi.graph.AreteGraph 1 3 > ../PrintNoeud/A1_3.txt &
echo '*** Creation arete 1 3 OK, pid '$!' ***'
wait $!

echo '*** Creation arete 2 4 ***'
java -Djava.security.policy=../mypolicy rmi.graph.AreteGraph 2 4 > ../PrintNoeud/A2_4.txt &
echo '*** Creation arete 2 4 OK, pid '$!' ***'
wait $!

echo '*** Creation arete 2 5 ***'
java -Djava.security.policy=../mypolicy rmi.graph.AreteGraph 2 5 > ../PrintNoeud/A2_5.txt &
echo '*** Creation arete 2 5 OK, pid '$!' ***'
wait $!

echo '*** Creation arete 3 9 ***'
java -Djava.security.policy=../mypolicy rmi.graph.AreteGraph 3 9 > ../PrintNoeud/A3_9.txt &
echo '*** Creation arete 3 9 OK, pid '$!' ***'
wait $!

echo '*** Creation arete 4 6 ***'
java -Djava.security.policy=../mypolicy rmi.graph.AreteGraph 4 6 > ../PrintNoeud/A4_6.txt &
echo '*** Creation arete 4 6 OK, pid '$!' ***'
wait $!

echo '*** Creation arete 4 7 ***'
java -Djava.security.policy=../mypolicy rmi.graph.AreteGraph 4 7 > ../PrintNoeud/A4_7.txt &
echo '*** Creation arete 4 7 OK, pid '$!' ***'
wait $!

echo '*** Creation arete 5 8 ***'
java -Djava.security.policy=../mypolicy rmi.graph.AreteGraph 5 8 > ../PrintNoeud/A5_8.txt &
echo '*** Creation arete 5 8 OK, pid '$!' ***'
wait $!

echo '*** Creation arete 9 10 ***'
java -Djava.security.policy=../mypolicy rmi.graph.AreteGraph 9 10 > ../PrintNoeud/A9_10.txt &
echo '*** Creation arete 9 10 OK, pid '$!' ***'
wait $!

echo '*** Creation arete 9 11 ***'
java -Djava.security.policy=../mypolicy rmi.graph.AreteGraph 9 11 > ../PrintNoeud/A9_11.txt &
echo '*** Creation arete 9 11 OK, pid '$!' ***'
wait $!

echo '*** Creation arete 3 10 ***'
java -Djava.security.policy=../mypolicy rmi.graph.AreteGraph 3 10 > ../PrintNoeud/A3_10.txt &
echo '*** Creation arete 3 10 OK, pid '$!' ***'
wait $!

echo '*** Creation arete 8 10 ***'
java -Djava.security.policy=../mypolicy rmi.graph.AreteGraph 8 10 > ../PrintNoeud/A8_10.txt &
echo '*** Creation arete 8 10 OK, pid '$!' ***'
wait $!

echo '*** Creation arete 5 7 ***'
java -Djava.security.policy=../mypolicy rmi.graph.AreteGraph 5 7 > ../PrintNoeud/A5_7.txt &
echo '*** Creation arete 5 7 OK, pid '$!' ***'
wait $!

echo ''
echo '/***************************************/'
echo '/*        Envoi des messages           */'
echo '/***************************************/'
echo ''

echo '*** Envoi du message "Hello" a partir du noeud 2 ***'
java -Djava.security.policy=../mypolicy rmi.graph.SendMessageGraph 2 1 hello &
echo '*** Envoi du message "Test" a partir du noeud 3 ***'
java -Djava.security.policy=../mypolicy rmi.graph.SendMessageGraph 3 2 test &
echo '*** Fin des envois des messages ***'
wait $!

echo ''
echo "Appuyer sur Entrée pour terminer..."
read a
echo '*** fermeture des java ***'
kill ${list_pid[*]}
echo '*** fermeture du registry ***'
kill $pid_registry